package collection;

import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;
import jdk.nashorn.internal.objects.NativeDebug;
import sun.net.www.content.text.Generic;

import java.util.ArrayList;
import java.util.List;

public class GenericDemo<T> {//泛型类
    private T key;

    public GenericDemo(T key){
        this.key=key;
    }

    public T getKey(){
        return key;
    }


    public static void main(String[] args) {
        GenericDemo<Integer> gen=new GenericDemo(123456);
        GenericDemo<String> eri=new GenericDemo("hello!java");
        System.out.println(gen.getKey());
        System.out.println(eri.getKey());

        List<String> arr=new ArrayList<>();//arr引用 ArrayList,ArrayList可以存放任何类型
        arr.add("adc");
        arr.add("def");
        //arr.add(100);
        for (int i = 0; i <arr.size() ; i++) {
            System.out.println(arr.get(i));//该列表中指定位置的元素
        }
        List<String> lis=new ArrayList<String>();
        List<Integer> lit=new ArrayList<Integer>();

        Class classStringArrayList=lis.getClass();
        Class classIntegerArrayList=lit.getClass();
        if (classStringArrayList.equals(classIntegerArrayList))
            System.out.println("类型相同");




    }


}
